import requests

import config.path_cfg as cfg


class EmpApi(object):
    admin_login_body = {
        "mobile": cfg.ADMIN_ACCOUNT,
        "password": cfg.ADMIN_PWD
    }

    def __init__(self, path_params=""):
        self.login_url = cfg.IHRM_URL + cfg.LOGIN_URL
        self.add_url = cfg.IHRM_URL + cfg.EMP_URL
        self.query_url = cfg.IHRM_URL + cfg.EMP_URL + '/' + path_params
        self.modify_url = cfg.IHRM_URL + cfg.EMP_URL + '/' + path_params
        self.delete_url = cfg.IHRM_URL + cfg.EMP_URL + '/' + path_params

    def login_request(self, body):
        return requests.post(self.login_url, json=body)

    def get_token(self):
        return self.login_request(self.admin_login_body).json().get('data')

    def get_headers(self):
        return {'Authorization': self.get_token()}

    def emp_add_request(self, body):
        return requests.post(self.add_url, json=body, headers=self.get_headers())

    def emp_query_request(self):
        return requests.get(self.query_url, headers=self.get_headers())

    def emp_modify_request(self, body):
        return requests.put(self.modify_url, json=body, headers=self.get_headers())

    def emp_delete_request(self):
        return requests.delete(self.delete_url, headers=self.get_headers())
